package cn.kmsoft.spatialboot.config;

import io.swagger.annotations.Api;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author
 * @date 2017/11/21
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    private static final Log logger = LogFactory.getLog(SwaggerConfig.class);
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                //.select().apis(RequestHandlerSelectors.any())
                .apiInfo(apiInfo()).select()
                //扫描所有有注解的api
                //.apis(RequestHandlerSelectors.withClassAnnotation(ApiOperation.class))
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("空间套合分析API文档")
                .description("本服务基于postgis pg_geometry实现空间叠加分析、空间查询、空间统计等接口")
                .termsOfServiceUrl("http://localhost:8082/spatialboot4pg/index")
                .contact(new Contact("wangq", "", "cqwensten@163.com"))
                .version("2.0.0")
                .build();
    }
}
